package com.platform.hjt.sys.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.hjt.tools.dao.Page;
import com.hjt.tools.dao.PropertyFilter;
import com.platform.hjt.base.controller.ReturnBody;
import com.platform.hjt.base.service.BaseService;
import com.platform.hjt.sys.dao.SysCompanyModelDAO;
import com.platform.hjt.sys.dao.SysModelDAO;
import com.platform.hjt.sys.dao.SysUserModelDAO;
import com.platform.hjt.sys.model.SysCompanyModel;
import com.platform.hjt.sys.model.SysModel;

@Service
public class SysModelService extends BaseService{

	@Resource
	private SysModelDAO sysModelDAO;
	@Resource
	private SysCompanyModelDAO sysCompanyModelDAO;
	@Resource
	private SysUserModelDAO sysUserModelDAO;
	
	public ReturnBody delSysModel(SysModel sysModel){
		sysModel.setIsDel(true);
		sysModelDAO.updatePerproties(sysModel);
		return  new ReturnBody(true, "删除成功");
	}
	
	public List<SysModel> getSysModelAll(){
		return sysModelDAO.findBy("isDel", false);
	}
	
	public List<SysModel> getCompanyModel(String companyId){
		String hql = "select t from SysModel t, SysCompanyModel s where t.isDel=false and t.sysModelId=s.sysModel.sysModelId and s.sysCompanyInfo.sysCompanyInfoId=?";
		return sysModelDAO.find(hql, companyId);
	}
	
	public List<SysCompanyModel> getCompanyModelList(String companyId){
		return sysCompanyModelDAO.findBy("sysCompanyInfo.sysCompanyInfoId", companyId);
	}
	
	public List<SysModel> getUserModel(String userInfoId){
		String hql = "select t from SysModel t, SysUserModel s where t.isDel=false and t.sysModelId=s.sysModel.sysModelId and s.sysUserInfo.sysUserInfoId=?";
		return sysModelDAO.find(hql, userInfoId);
	}
	
	public Page<SysModel> getSysModelList(Page<SysModel> page, List<PropertyFilter> propertyFilterList){
		return sysModelDAO.findPage(page, propertyFilterList);
	}
	
	public List<SysModel> getSysModelList(List<PropertyFilter> filters){
		return sysModelDAO.find(filters);
	}
	
	public SysModel getSysModel(List<PropertyFilter> filters){
		return sysModelDAO.findUniqueBy(filters);
	}
	
	public SysModel getSysModel(String propertyName, Object value){
		return sysModelDAO.findUniqueBy(propertyName, value);
	}
	
}
